package com.management.platform.util;

import com.management.platform.enums.LoginResultEnum;
import org.springframework.stereotype.Component;

@Component
public class ResultCode {
  //返回状态码
  private String code;

  //返回信息
  private String msg;

  //返回数据
  private Object data;

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  public ResultCode(){

  }

  public ResultCode(String code, String msg) {
    this.code = code;
    this.msg = msg;
  }

  public ResultCode(LoginResultEnum resultEnum) {
    this.code = resultEnum.getCode();
    this.msg = resultEnum.getMsg();
  }

  /**
   * 返回登录失败信息码
   * @param resultEnum
   * @return
   */
  public ResultCode error(LoginResultEnum resultEnum){
    ResultCode resultCode = new ResultCode(resultEnum);

    return resultCode;
  }

  /**
   * 返回登录成功信息码
   * @param o
   * @return
   */
  public ResultCode success(Object o){
    ResultCode resultCode = new ResultCode();
    resultCode.setCode("200");
    resultCode.setMsg("success");
    resultCode.setData(o);
    return  resultCode;
  }

  public ResultCode success(){
    return new ResultCode().success(null);
  }

  @Override
  public String toString() {
    return "ResultCode{" +
        "code='" + code + '\'' +
        ", msg='" + msg + '\'' +
        ", token=" + data +
        '}';
  }


}
